/*
 * DemoFrame.java
 *
 * Created on June 27, 2007, 12:06 PM
 */

package tooltip.demo;

import java.awt.Desktop;
import java.io.File;
import java.net.URL;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LayoutStyle;
import javax.swing.PopupFactory;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.border.TitledBorder;

import tooltip.HyperLink;
import tooltip.NonRectanglePopupFactory;

/**
 */
public class DemoFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/** Creates new form DemoFrame */
	public DemoFrame() {
		initComponents();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// <editor-fold defaultstate="collapsed" desc=" Generated Code
	// ">//GEN-BEGIN:initComponents
	private void initComponents() {
		jPanel1 = new JPanel();
		hyperLink1 = new HyperLink();
		jLabel1 = new JLabel();
		jButton1 = new JButton();

		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		jPanel1.setBorder(BorderFactory.createTitledBorder(BorderFactory
				.createEtchedBorder(), "Tweaking Tooltips",
				TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0,
						11), java.awt.Color.black));
		hyperLink1.setText("Let's Swing Java");
		hyperLink1.setWebShot(new ImageIcon(getClass().getResource(
				"/tooltip/demo/1.png")));
		hyperLink1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				hyperLink1ActionPerformed(evt);
			}
		});

		jLabel1
				.setText("<html>\n<body>\n<h3>Welcome to swing demo application!</h3>\n<ul>\n<li>Move your mouse over here and hold it for a little while, you'll see the tweaking-shaped tooltip window.</li>\n<li>Move your mouse over \"Let's Swing Java\", you'll see a clickable hyper link. And you can also see a web screenshot thumb there.</li>\n</ul>\n<strong><em>Enjoy Swing Programming</em></strong>\n</body>\n</html>\n");
		jLabel1
				.setToolTipText("<html>\n<body>\n<h3>Welcome to the swing demo application!</h3>\n<p>\nNow you have seen the tooltip.\n<p>\nLife is hilarious:)\n<p>\nHurray!\n</body>\n</html>");

		GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(
				GroupLayout.Alignment.LEADING).addGroup(
				jPanel1Layout.createSequentialGroup().addContainerGap()
						.addGroup(
								jPanel1Layout.createParallelGroup(
										GroupLayout.Alignment.LEADING)
										.addComponent(jLabel1,
												GroupLayout.DEFAULT_SIZE, 305,
												Short.MAX_VALUE).addComponent(
												hyperLink1,
												GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE))
						.addContainerGap()));
		jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(
				GroupLayout.Alignment.LEADING)
				.addGroup(
						jPanel1Layout.createSequentialGroup().addComponent(
								jLabel1).addPreferredGap(
								LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(hyperLink1,
										GroupLayout.PREFERRED_SIZE,
										GroupLayout.DEFAULT_SIZE,
										GroupLayout.PREFERRED_SIZE)
								.addContainerGap(GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE)));

		jButton1.setText("Exit");
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});

		GroupLayout layout = new GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup().addContainerGap(296,
						Short.MAX_VALUE).addComponent(jButton1)
						.addContainerGap()).addGroup(
				layout.createSequentialGroup().addContainerGap().addComponent(
						jPanel1, GroupLayout.PREFERRED_SIZE,
						GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addContainerGap(GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE)));
		layout.setVerticalGroup(layout.createParallelGroup(
				GroupLayout.Alignment.LEADING).addGroup(
				GroupLayout.Alignment.TRAILING,
				layout.createSequentialGroup().addContainerGap().addComponent(
						jPanel1, GroupLayout.PREFERRED_SIZE,
						GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(
								LayoutStyle.ComponentPlacement.RELATED, 45,
								Short.MAX_VALUE).addComponent(jButton1)
						.addContainerGap()));
		pack();
	}// </editor-fold>//GEN-END:initComponents

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton1ActionPerformed
		System.exit(0);
	}// GEN-LAST:event_jButton1ActionPerformed

	private void hyperLink1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_hyperLink1ActionPerformed
		try {
			Desktop.getDesktop().browse(
					new URL("http://blog.sina.com.cn/swingjava").toURI());
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}// GEN-LAST:event_hyperLink1ActionPerformed

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		try {
			PopupFactory.setSharedInstance(new NonRectanglePopupFactory());
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception ex) {
		}
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new DemoFrame().setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private HyperLink hyperLink1;
	private JButton jButton1;
	private JLabel jLabel1;
	private JPanel jPanel1;
	// End of variables declaration//GEN-END:variables

}
